﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ArtheaEngine.Model;
using ArtheaServer.Creation;
using ArtheaEngine;

namespace ArtheaServer.Commands
{
    public class EditCommand : Command
    {
        public EditCommand()
            : base("edit", "edits entities in the world", ArtheaHelper.MaxLevel)
        { }

        public override void Execute(Character ch, ArtheaEngine.Argument argument)
        {
            var arg = argument.Next();
            Player p = ch as Player;

            if(p == null) return;

            Connection conn = p.Account.Connection as Connection;

            if (arg.IsPrefixOf("character"))
            {
                var vict = ch.World.Characters.SingleOrDefault(x => x.Name.StartsWith(argument));
                if (vict == null)
                {
                    ch.WriteLine("No such character.");
                    return;
                }
                conn.Editing = new CharEditor(conn, vict);
                conn.Editing.Show();
                return;
            }

            if (arg.IsPrefixOf("room"))
            {
                var room = ch.Room;

                conn.Editing = new RoomEditor(conn, room);

                conn.Editing.Show();
                return;
            }

            conn.WriteLine("Syntax: edit help");
            conn.WriteLine("        edit room");
            conn.WriteLine("        edit character");
        }
    }

    public class CreateCommand : Command
    {
        public CreateCommand()
            : base("create", "creates an entity", ArtheaHelper.MaxLevel)
        { }


        public override void Execute(Character ch, Argument argument)
        {
            var arg = argument.Next();

            if (arg.IsPrefixOf("character"))
            {
                var npc = new NonPlayer();

                npc.Name = "NewMob";

                npc.World.Context.AddToCharacters(npc);

                
            }
        }
    }
}
